package com.xiaoma.tpo.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xiaoma.tpo.dao.TagsDao;
import com.xiaoma.tpo.dao.UserBdpushBindDao;
import com.xiaoma.tpo.dao.UserMessageDao;
import com.xiaoma.tpo.dao.UserTagDao;
import com.xiaoma.tpo.domain.Tags;
import com.xiaoma.tpo.domain.User;
import com.xiaoma.tpo.domain.UserTag;

/**
 * Created by Owner on 2015/5/6.
 */
@Service
public class TagsService {
    @Autowired
    private TagsDao tagsDao;

    @Autowired
    private UserTagDao userTagDao;

    @Autowired
    private UserBdpushBindDao userBdpushBindDao;

    @Autowired
    private UserMessageDao userMessageDao;


    /**
     * 设置标签
     * @param user
     * @param tag
     */
    public void setTag(User user,String tag){
        Tags tags = new Tags();
        tags.setTagName(tag);
        List<Tags> rs = tagsDao.findByColumns(tags);
        UserTag ut = new UserTag();
        ut.setUserId(user.getId());
        if(rs.size()>0){
            ut.setTagId(rs.get(0).getId());
        }else{
            int tagid = tagsDao.insert(tags);
            ut.setTagId(tagid);
        }
        //判断是否存在这个标签
        if(userTagDao.findByColumns(ut).size()>0){

        }else{
            userTagDao.insert(ut);
        }

    }
}
